package trees;

import java.util.ArrayList;
import java.util.List;

public class HasPathSum {
    List<List<Integer>> result = new ArrayList<>();

    public boolean hasPathSum(TreeNode root, int targetSum) {
        List<Integer> start = new ArrayList<>();
        dfs(root, start);
        System.out.println(result);
        return false;
    }

    public void dfs(TreeNode root, List<Integer> val) {
        if (root == null) {
            return;
        }

        val.add(root.val);

        if (root.left == null && root.right == null) {
            result.add(val);
            val = new ArrayList<>();
        }

        dfs(root.left, val);
        dfs(root.right, val);
    }

    public static void main(String[] args) {
        TreeNode node = new TreeNode(5);
        node.left = new TreeNode(4);
        node.right = new TreeNode(8);
        node.right.right = new TreeNode(4);

        node.left.left.left = new TreeNode(7);
        node.left.left.right = new TreeNode(2);

        node.right.right.right = new TreeNode(1);

        HasPathSum hasPathSum = new HasPathSum();
        hasPathSum.hasPathSum(node, 22);
    }
}
